<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
    .fixed-table-body {
        height: calc(73vh);
    }

    .fixed-table-footer {
        border-top: 0;
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div id="flexSearchBox" class="collapse out col-sm-12 search-box">
        <form id="user-form">
            <div class="select-list">
                <ul>

                    <li>
                        productName：<input class="reset" type="text" name="productName"/>
                    </li>
                    <li>
                        productCategories：<select name="productClass" th:with="type=${@dict.getType('erp_product_class')}">
                        <option value="">all</option>
                        <option th:each="e : ${type}" th:text="${e['dictLabel']}" th:value="${e['dictValue']}"></option>
                    </select>
                    </li>
                    <li>
                        productType：<select name="productType" th:with="type=${@dict.getType('erp_product_type')}">
                        <option value="">all</option>
                        <option th:each="e : ${type}" th:text="${e['dictLabel']}" th:value="${e['dictValue']}"></option>
                    </select>
                    </li>
                    <li>
                        mainSKU：<input class="reset" type="text" name="mainSKU"/>
                    </li>
                    <li>
                        unionSKU：<input class="reset" type="text" name="unionSKU"/>
                    </li>
                    <li>
                        EAN：<input class="reset" type="text" name="eAN"/>
                    </li>
                    <li class="time">
                        <label>inventoryDate:</label>
                        <input type="text" id="startTime" class="time-input reset" placeholder="start date"
                               name="beginTakingDate"/>
                        <span>to</span>
                        <input type="text" id="endTime" class="time-input reset" placeholder="end date"
                               name="endTakingDate"/>
                    </li>
                    <li>
                        <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search()"><i
                                class="fa fa-search"></i>&nbsp;search</a>
                        <a class="btn btn-primary btn-rounded btn-sm reset-booton"><i
                                class="glyphicon glyphicon-repeat"></i>&nbsp;reset</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>

    <div class="btn-group hidden-xs" id="toolbar" role="group">
        <a class="btn btn-outline btn-success btn-rounded"  onclick="SweepCodeStockTaking('StockTaking 扫码盘点')"
           shiro:hasPermission="module:stockTaking:editSweepCode" >
            <i class="fa fa-print"></i> scanInventory
        </a>
        <a class="btn btn-outline btn-warning btn-rounded" onclick="showProductName()">
            <i class="glyphicon glyphicon-zoom-in"></i> showFullProductName
        </a>
        <a class="btn btn-outline btn-info btn-rounded flex-botton" data-toggle="collapse" data-target="#flexSearchBox">
            <i class="glyphicon glyphicon-chevron-down">unfoldSearch
            </i>
        </a>
    </div>

    <div class="col-sm-12 select-info table-responsive">
        <table id="bootstrap-table" class="table text-nowrap table-hover" data-height="770"
               data-mobile-responsive="true"></table>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var edit_stockTaking = [[${@permission.hasPermi('module:stockTaking:edit')}]];
    var types = [[${@dict.getType('erp_product_class')}]];
    var types1 = [[${@dict.getType('erp_product_type')}]];


    var prefix = ctx + "module/products";
    $(function () {
        var options = {
            url: prefix + "/stockTaking_list",
            updateInventoryUrl: prefix + "/edit_stockTaking/{id}",
            print_test: prefix + "/print_test/{mainSKU}/{productName}/{size}",
            modalName: "库存盘点",
            showFooter: true,
            columns: [{
                checkbox: true
            }, {
                field: 'id',
                align: 'center',
                title: 'id',
                visible: false
            },
                {
                    title: 'serialNumber',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                    },
                    footerFormatter: function (value) {
                        return 'total';
                    }
                },
                {
                    title: 'operation',
                    clickToSelect : false,
                    align: 'center',
                    width: 80,
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn label-danger btn-xs" href="#" onclick="print_test(\'' + "nobeach" + '\'' + ',\'' + row.mainSKU + '\'' + ',\'' + row.productName + '\')"><i class="glyphicon glyphicon-print"></i> brandLabel</a>');
                        actions.push('<a class="btn btn-info btn-xs ' + edit_stockTaking + '" href="#" onclick="editInventory(\'' + row.id + '\')"><i class="fa fa-edit"></i>adjustm</a> ');
                        return actions.join('');
                    }
                },

                {
                    field: 'picUrl',
                    align: 'center',
                    sortable: true,
                    title: 'prictue',
                    clickToSelect : false,
                    formatter: function (value, row, index) {
                        return '<div id="image_links">' +
                            '<a href="/profile/product/' + value + '" title="' + row.productName + '" data-gallery="">' +
                            '<img class="img-rounded" width="60px" height="50px" src="/profile/product/' + value + '"></a>' +
                            '</div>';
                    }
                },
                {
                    field: 'productName',
                    align: 'center',
                    sortable: true,
                    clickToSelect : false,
                    title: '<span class="globalSearch_column">productName</span>',
                    formatter: function (value, row, index) {
                        if (fal){
                            return '<div class="popover_productname" data-toggle="popover" data-placement="top" data-content="'+value+'">'+value+'</div>';
                        }else {
                            return '<div class="popover_productname" data-toggle="popover" data-placement="top" data-content="'+value+'">'+sub_hidden(value)+'</div>';

                        }
                    }
                },
                {
                    field: 'productClass',
                    title: 'productCategories',
                    sortable: true,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(types, value);
                    }
                },
                {
                    field: 'productType',
                    title: 'productType',
                    sortable: true,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(types1, value);
                    }
                },
                {
                    field: 'mainSKU',
                    align: 'center',
                    sortable: true,
                    title: '<span class="globalSearch_column">mainSKU</span>'
                },
                {
                    field: 'unionSKU',
                    align: 'center',
                    sortable: true,
                    title: '<span class="globalSearch_column">unionSKU</span>'
                },
                {
                    field: 'submitQuantity',
                    align: 'center',
                    sortable: true,
                    title: 'confirmQuantity',
                    footerFormatter: function (value) {
                        return calculateLineTotalAsServer(value, $.table.sumRows.submitQuantity);
                    }
                },
                {
                    field: 'onhandDb',
                    title: 'inventory',
                    align: 'center',
                    sortable: true,
                    footerFormatter: function (value) {
                        return calculateLineTotalAsServer(value, $.table.sumRows.onhand);
                    }
                },
                {
                    field: 'shareQuantity',
                    align: 'center',
                    sortable: true,
                    title: 'inventoryQuantity',
                    footerFormatter: function (value) {
                        return calculateLineTotalAsServer(value, $.table.sumRows.shareQuantity);
                    }
                },
                {
                    field: 'takingDate',
                    align: 'center',
                    sortable: true,
                    title: 'inventoryDate'
                },
                {
                    field: 'companyName',
                    align: 'center',
                    sortable: true,
                    title: 'company'
                }],
            onLoadSuccess: function (item, $element) {
                $('.fixed-table-footer').addClass("totalRowBackground-color");//合计行添加颜色

                initialize_image();
                //初始化提示框方法
                initialize_popover();
            },
        };
        $.table.init(options);

    });

    /*商品以及库存管理-修改库存*/
    function editInventory (id) {
        var url = $.table._option.updateInventoryUrl.replace("{id}", id);
        $.modal.open("修改库存" + $.table._option.modalName, url);
    }

    //扫码盘点弹出层
    function SweepCodeStockTaking(title,url){
        var sign = title.split(" ");
        var url = prefix+"/toSweepCodeStockTaking?flag="+sign[0];
        $.modal.open("<h3 style='margin-top: 10px'>"+sign[1]+"</h3>", url);
    }

    /*展示所有名称*/
    var fal = false;
    var fal_num = 0;
    function showProductName(){
        if (fal_num % 2 == 0){
            fal = true;
        }else {
            fal = false;
        }
        fal_num++;
        $("#bootstrap-table").bootstrapTable('refresh');
    }

    //暂时使用
    function print_test (state, mainSKU, productName,size) {
        var title;
        //批量打印
       /* if (state == "beach") {
            var rows = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
            if (rows.length == 0) {
                $.modal.alertWarning("Please select at least one record");
                return;
            }
            ids = getBootstrapTableValueAsRow('id', rows);
            createDate = getBootstrapTableValueAsRow('createDate', rows);


            title = "batch print"

        } else {*/
            title = "print"
        /*}
*/

        var url = $.table._option.print_test.replace("{mainSKU}", mainSKU)
            .replace("{productName}", productName).replace("{size}", size);

        $.modal.open(title + $.table._option.modalName, url);
    }
</script>
</body>
</html>